package com.yx.fsysserver.file.controller;

import com.yx.fsysserver.common.result.JsonResult;
import com.yx.fsysserver.file.service.AliPlayService;
import com.yx.fsysserver.file.vo.AddFileInfoVo;
import com.yx.fsysserver.file.vo.UploadFileInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 阿里云视频点播加密
 * @author cuihao
 * @date  2017/3/3.
 */
@RestController
@RequestMapping("/aliPlay")
public class AliPlayController {
    private Logger log = LoggerFactory.getLogger(AliPlayController.class);

    @Autowired
    private AliPlayService aliPlayService;

    /**
     * 上传前,从阿里点播视频获取上传权限和上传地址
     *
     * @param fileInfo
     * @return
     */
    @RequestMapping(value = "/getUploadInfo", method = RequestMethod.POST)
    public JsonResult getUploadInfo(@RequestBody UploadFileInfo fileInfo) {
        return aliPlayService.getUploadInfo(fileInfo);
    }

    /**
     * 保存文件到数据库
     * @param vo
     * @return
     */
    @RequestMapping(value = "/savefile", method = RequestMethod.POST)
    public JsonResult savefile(@RequestBody AddFileInfoVo vo) {
        return aliPlayService.savefile(vo);
    }

    /**
     * 获取播放凭证
     *
     * @param videoId 视频id
     * @return
     */
    @RequestMapping(value = "/getPlayAuth", method = RequestMethod.GET)
    public JsonResult getPlayAuth(String videoId) {
        return aliPlayService.getPlayAuth(videoId);
    }

    /**
     * 获取播放地址
     *
     * @param videoId 视频id
     * @return
     */
    @RequestMapping(value = "/getPlayAddress", method = RequestMethod.GET)
    public JsonResult getPlayAddress(String videoId) {
        return aliPlayService.getPlayAddress(videoId);
    }

    /**
     * 获取视频信息
     *
     * @param videoId 视频id
     * @return
     */
    @RequestMapping(value = "/getVideoInfo", method = RequestMethod.GET)
    public JsonResult getVideoInfo(String videoId) {
        return aliPlayService.getVideoInfo(videoId);
    }

    /**
     * 获取源文件地址
     *
     * @param videoId 视频id
     * @return
     */
    @RequestMapping(value = "/getMezzanineInfo", method = RequestMethod.GET)
    public JsonResult GetMezzanineInfo(String videoId) {

        return new JsonResult(true, "success",aliPlayService.GetMezzanineInfo(videoId));
    }

}
